package com.example.s.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class MyRecyclerViewAdapter<T> extends RecyclerView.Adapter<InnerHolder> {
    private List<T> mData;
    private int mItemLayout;

    public MyRecyclerViewAdapter(List<T> mData, int itemLayout) {
        this.mData = mData;
        this.mItemLayout = itemLayout;
    }



    @NonNull
    @Override
    public InnerHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new InnerHolder(LayoutInflater.from(viewGroup.getContext()).inflate(mItemLayout, viewGroup, false));
    }


    @Override
    public void onBindViewHolder(@NonNull InnerHolder myViewHolder, int i) {
        handleData(myViewHolder,mData.get(i));
    }
    public abstract void handleData(InnerHolder holder, T item);

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void setmData(List<T> data) {
        this.mData.clear();
        this.mData.addAll(data);
        notifyDataSetChanged();
    }




}
